﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.ModFlow.Domain.DomainLayer
{
    [Serializable]
    public class GridLayer
    {

        /// <summary>
        /// 初始化一个图层，用于表示水网格的相关网格类型参数数据
        /// </summary>
        /// <param name="rowi">行数</param>
        /// <param name="colj">列数</param>
        public GridLayer(int rowi,int colj)
        {
            //_cells = new Cell[deli, delj];

            //_botElevation=new double[rowi,colj];

            _iBound=new int[rowi,colj];
            
            _initHead=new double[rowi,colj];


           

           

         

          


            _confiningBedElevation=new double [rowi,colj];


            for (int i = 0; i < rowi; i++)
            {
                for (int j = 0; j < colj; j++)
                {
                    _iBound[i, j] = 1;

                    _initHead[i,j] = 0;

                   

                   
                    


                   



                    _confiningBedElevation[i,j]=0;
                    
                }
                
            }




            this._nRows = rowi;

            this._nCols = colj;




 
        }


        #region 属性数据区


        WaterGrid _parentGrid;

        public WaterGrid ParentGrid
        {
            get { return _parentGrid; }
            set { _parentGrid = value; }
        }



      


        /// <summary>
        /// 应对可能到来的排序索引
        /// </summary>
        public int LayerIndex
        {
            get {

                return this._parentGrid.Layers.IndexOf(this);
            
            }
           
        }





        LAYERTYPE _layerType = LAYERTYPE.NOCONFINED;

        public LAYERTYPE LayerType
        {
            get { return _layerType; }
            set { _layerType = value; }
        }



        int _nRows;

        public int NRows
        {
            get { return _nRows; }
            set { _nRows = value; }
        }
        int _nCols;

        public int NCols
        {
            get { return _nCols; }
            set { _nCols = value; }
        }


        int[,] _iBound;

        /// <summary>
        /// 边界条件
        /// </summary>
        public int[,] IBound
        {
            get { return _iBound; }
            set { _iBound = value; }
        }


        double[,] _initHead;

        /// <summary>
        /// 初始水头
        /// </summary>
        public double[,] InitHead
        {
            get { return _initHead; }
            set { _initHead = value; }
        }

        

       

     


        ///// <summary>
        ///// 图层本身的顶部高程信息
        ///// </summary>
        //public double[,] TopElevation
        //{
        //    get {


        //       //int iLayer= this._parentGrid.Layers.IndexOf(this);

        //       //double[,] top= this._parentGrid.Elevations[iLayer];


        //       // return top; 

                
            
            
        //    }
            
        //}


        /// <summary>
        /// 指示本层是否是最上面一层
        /// </summary>
        public bool IsTopLayer
        {
            get{


                int index = this.LayerIndex;
                if (index == 0)
                {
                    return true;

                }
                else
                {
                    return false;
                }
               

            }
            

 
        }

        /// <summary>
        /// 指示本层是否是最后一层
        /// </summary>
        public bool IsBottomLayer
        {
            get
            {
                int index = this.LayerIndex;
                if (index == this.ParentGrid.Layers.Count-1)
                {
                    return true;

                }
                else
                {
                    return false;
                }

               
               
            }



        }


        //double[,] _botElevation;

        ///// <summary>
        ///// 图层本身的底部高程信息
        ///// </summary>

        //public double[,] BotElevation
        //{
        //    get {

        //        return _botElevation;
              
            
        //    }
          
        //}


        bool _isHaveConfiningBed = false;

        /// <summary>
        /// 只是下方是否含有隔水层
        /// </summary>
        public bool IsHaveConfiningBed
        {
            get { return _isHaveConfiningBed; }
            set { _isHaveConfiningBed = value; }
        }




        double[,] _confiningBedElevation;

        public double[,] ConfinedBedElevation
        {
            get { return _confiningBedElevation; }
            set { _confiningBedElevation = value; }
        }




        public int GetConstantCellCount()
        {
            int n = 0;

            for (int i = 0; i < this._nRows; i++)
            {
                for (int j = 0; j < this._nCols; j++)
                {
                    if (this._iBound[i,j]==-1)
                    {
                        n++;
                        
                    }

                    
                }
                
            }


            return n;


        }


        #endregion

    }
}
